package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.dao.MenuDao;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：gaoqiang
 * @date ：Created in 2019/7/3
 * @description ：
 * @version: 1.0
 */
@Service
@Slf4j
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;



    @Override
    public List<Map<String, Object>> findMenuByRoleId(Integer id) {
        List<Map<String, Object>> menuList=new ArrayList<>();
        List<Map<String,String>> fuMenu = menuDao.findFuMenuById(id);
        for (Map<String, String> menu : fuMenu) {
            Map<String, Object> map=new HashMap<>();
            String fupath = menu.get("path");
            String name = menu.get("name");
            String icon = menu.get("icon");
            map.put("path",fupath);
            map.put("title",name);
            map.put("icon",icon);
            List<Map<String, String>> ziMenu = menuDao.findZiMenuByid(id);
            List<Map<String,Object>> list=new ArrayList<>();
            for (Map<String, String> zimenu : ziMenu) {
                String zipath = zimenu.get("path");
                String path = zipath.substring(1, 2);
                if (path.equals(fupath)) {
                    String name1 = zimenu.get("name");
                    String linkUrl = zimenu.get("linkUrl");
                    Map<String, Object> zimap = new HashMap<>();
                    zimap.put("path", zipath);
                    zimap.put("title", name1);
                    zimap.put("linkUrl", linkUrl);
                    zimap.put("children", null);
                    list.add(zimap);
                }
            }
            map.put("children",list);
            menuList.add(map);
        }
        log.debug("菜单:{}",menuList);
        return menuList;
    }
}
